<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>2_回调形式refs</title>
</head>
<body>
<div id="test"></div>

<script type="text/javascript" src="../js/react.development.js"></script>
<script type="text/javascript" src="../js/react-dom.development.js"></script>
<script type="text/javascript" src="../js/babel.min.js"></script>

<script type="text/babel">

    class Demo extends React.Component {

        state={isHot:true}
        showData = () => {
            const {input1} = this
            alert(input1.value)
        }
        showData2 = () => {
            const {input2} = this
            alert(input2.value)
        }
        changeWeather = ()=>{
            const {isHot} = this.state

            this.setState({isHot:!isHot})
        }
        saveInput = (c)=>{
            this.input1 = c;
            console.log('@',c)
        }

        render() {
            const {isHot} = this.state
            return (
                <div>
                    <h1>今天天气很{isHot ? '炎热' : '寒冷'}</h1>
                    <button onClick={this.changeWeather}>点击我切换天气</button> &nbsp;
                    {/*<input ref={c => this.input1 = c} type="text" placeholder="点击按钮提示数据"/>&nbsp;*/}
                    <input ref={this.saveInput} type="text" placeholder="点击按钮提示数据"/>&nbsp;
                    <button onClick={this.showData}>点击我提示左边数据</button> &nbsp;
                    <input ref={c => this.input2 = c} onBlur={this.showData2} type="text" placeholder="失去焦点提示数据"/>&nbsp;
                </div>
            )
        }
    }


    ReactDOM.render(<Demo/>, document.getElementById('test'))

</script>
</body>
</html>
